package game.action;

import game.frame.Direction;
import game.frame.WorkPanel;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class WorkPanelKeyAction implements KeyListener {

	public void keyTyped(KeyEvent e) {
		System.out.println("Key Typed ! >>>>  " + e.getKeyChar());
	}

	public void keyPressed(KeyEvent e) {
		controlSnake(e.getSource(), e);
	}

	public void keyReleased(KeyEvent e) {
		
	}
	
	
	private void controlSnake(Object obj, KeyEvent e) {
		if(obj instanceof WorkPanel) {
			WorkPanel wp = (WorkPanel) obj;
			
			switch (e.getKeyCode()) {
			case KeyEvent.VK_UP:
				wp.setDir(Direction.Up);
				break;
			case KeyEvent.VK_DOWN:
				wp.setDir(Direction.Down);		
				break;
			case KeyEvent.VK_LEFT:
				wp.setDir(Direction.Left);
				break;
			case KeyEvent.VK_RIGHT:
				wp.setDir(Direction.Right);
				break;

			default:
				break;
			}
			
			wp.updateSnakePos();
		}
	}
}
